/*
 * Filename : 24xx512.h
 * Hardware : Controller  -> P89V51RD2
 *            XTAL        -> 18.432 MHz
 *            Mode        -> 6 Clock/MC
 * I/O      : SDA         -> P2.7
 *            SCL         -> P2.6
 * Compiler : SDCC
 * Author   : sci-3d@hotmail.com
 * Date		: 23/08/06
 */

#define DS1307_SDA PIN_C4
#define DS1307_SCL PIN_C3
#use i2c(master, sda=DS1307_SDA, scl=DS1307_SCL)

#define EEPROMS_ID 0xA0	/* Microchip 24xx512 */

BYTE EEPROM_get(unsigned int addr)
{
	//unsigned char dat;
	BYTE dat;

	i2c_start();            /* Start i2c bus */

	i2c_write(EEPROMS_ID);   /* Connect to EEPROM */
	i2c_write(addr&0xF0);	 /* Request RAM address (Hight byte) */
	i2c_write(addr&0x0F);	 /* Request RAM address (Low byte) */

	i2c_start();			/* Start i2c bus */

	i2c_write(EEPROMS_ID+1);/* Connect to EEPROM for Read */
	dat = i2c_read();		/* Receive data */

//	i2c_noack();
printf("noacK");

	i2c_stop();				/* Stop i2c bus */

   return(dat);
}


void EEPROM_set(unsigned int addr, unsigned char val)
{
	i2c_start();

	i2c_write(EEPROMS_ID);   /* Connect to EEPROM */
	i2c_write(addr&0xF0);	 /* Request RAM address (Hight byte) */
	i2c_write(addr&0x0F);	 /* Request RAM address (Low byte) */

	i2c_write(val);			/* Write sec on RAM specified address */

	i2c_stop();           	/* Stop i2c bus */
}
